package com.yinNuo.collectWool.utils;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;

/**
 * @author: yinNuo
 * create at: 2021/12/16 上午11:16
 * @description: 中青安卓descbc解密工具类
 */
public class ZhongQingDesCbcUtils {

    public void aaa() {
//        String key = "6HPjSZFH";
        byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue()).getEncoded();
//		DES des = SecureUtil.des(key);
        DES des = new DES(Mode.CBC, Padding.NoPadding, "6HPjSZFH".getBytes(), "6HPjSZFH".getBytes());

        // 加密为16进制表示
//		String encryptHex = des.encryptHex(content);
        String encryptHex = "v9KveHJhUlCagirF/fZxG3bF/mqByz8mLnx9GKOr61SIdGp4iFvCrhdM2Z5qfh2tN31qiYfehao32IOG6/oa0JbNfaM/Mts+e7Td7SSJg0lE/dyurhhgsr8oDltClckWZng80aYkCpmhoTDM3DzW1uF6X5Jibv+xzL3rWLsUZeoX/DQkN/VObs7ZO5UV9vaMNIYpZKMeETRjUp5knNJlffe8JQ2kYmJjpkBn3l3CmQlvTxhIcJ3WoyXlo6zOKl67ueattla9rPh1FXNBcwIqjGPSiN0LCViYoeiWTptsbLU9K8vvGxNbTkFEOi6AnJ1zOGZEFV+vjjqUUmZkBVagg5OWhYaEuIlyWzS79jyhXRHxxJckfwPLbEHq9/594Xwe1WLPvyyo9UezXJUmriN7Z60aZYRUK2bC2YuTHObj/CjkcyVpZa32GFcSIgu4azRU65bJA8iB3j+rQToyibR2EwZLYTHmEN4PiCE5iuKqZU2WHhaAIYx5krLnW1OFaeFNxNvUsa1PH+Efp/GdLQNMg4XmhA176kTwkI47fhHD8I90FNw3goklX56EyRPhLuyQYF5QaeXWH0tDGKYGgavL6UyfQvdHfuDlQ+M4/++kuguqqApzn47kkFSxFX0Nn12QnEBesLTJJcUZQi7I4sIlDGP1hxrtNMupgP/hhRqunOyUN9WoTR3+jp7b3Jb1E8mqut6Qpn23bZkvqosUSX0HEM/tipy1vFpucU0w2Xh2T1MwD8zngedWvGb7UwpAnU21SOGTsjqwRRucGAJdCOqNKsTRxEy+22sd8fxwcEIQC5OjpOdniZ8eRSLpYcpLh0LH8cBKceqQf/Eu17t1n5BGGgIBnB2q+IZ1jOsTNrFeftNP7uoZD+fPJ9GWJCOiIG2c7sCJo5QB0K1aMOlT45MPdVqVvOK3ZQ2hRj6NU0xm6nhE+QvJ1fqs9Ho4ugXmy7YKbZnbVTJuBhbN1uQEJyFbuP6w481XB9+/8HxWq4lsesVRG4Lwrpfcp2hP7dMSY3IQVeEayax8h6uhhtSARXCO5gRNSxqdE9NTTpAFkTq+xQ7xuSln+0F6/peyMhDg60+94xTGMuQDSVPhsdrYyUQNaGgYsDdx5yDJ+qPDzGSyKP4N24xPOZLIaZy0ttoHeXteNZZuutUV8LrG6L5OR261yO0dX5K3EqDYnsva3n/+kDl8wRY22kRFaNETADWAuIQqwYLdWBAVG/A=";
        // 解密
        String decryptStr = des.decryptStr(encryptHex);
        //System.out.println(decryptStr);
    }

    /**
     * DES CBC加密数据
     * @param key 加密的密钥
     * @param content 要加密的内容
     */
    public static String desEncrypt(String key, String content) {
        DES des = new DES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), key.getBytes());

        // 加密为16进制表示
        return des.encryptHex(content);
//        String encryptHex = "v9KveHJhUlCagirF/fZxG3bF/mqByz8mLnx9GKOr61SIdGp4iFvCrhdM2Z5qfh2tN31qiYfehao32IOG6/oa0JbNfaM/Mts+e7Td7SSJg0lE/dyurhhgsr8oDltClckWZng80aYkCpmhoTDM3DzW1uF6X5Jibv+xzL3rWLsUZeoX/DQkN/VObs7ZO5UV9vaMNIYpZKMeETRjUp5knNJlffe8JQ2kYmJjpkBn3l3CmQlvTxhIcJ3WoyXlo6zOKl67ueattla9rPh1FXNBcwIqjGPSiN0LCViYoeiWTptsbLU9K8vvGxNbTkFEOi6AnJ1zOGZEFV+vjjqUUmZkBVagg5OWhYaEuIlyWzS79jyhXRHxxJckfwPLbEHq9/594Xwe1WLPvyyo9UezXJUmriN7Z60aZYRUK2bC2YuTHObj/CjkcyVpZa32GFcSIgu4azRU65bJA8iB3j+rQToyibR2EwZLYTHmEN4PiCE5iuKqZU2WHhaAIYx5krLnW1OFaeFNxNvUsa1PH+Efp/GdLQNMg4XmhA176kTwkI47fhHD8I90FNw3goklX56EyRPhLuyQYF5QaeXWH0tDGKYGgavL6UyfQvdHfuDlQ+M4/++kuguqqApzn47kkFSxFX0Nn12QnEBesLTJJcUZQi7I4sIlDGP1hxrtNMupgP/hhRqunOyUN9WoTR3+jp7b3Jb1E8mqut6Qpn23bZkvqosUSX0HEM/tipy1vFpucU0w2Xh2T1MwD8zngedWvGb7UwpAnU21SOGTsjqwRRucGAJdCOqNKsTRxEy+22sd8fxwcEIQC5OjpOdniZ8eRSLpYcpLh0LH8cBKceqQf/Eu17t1n5BGGgIBnB2q+IZ1jOsTNrFeftNP7uoZD+fPJ9GWJCOiIG2c7sCJo5QB0K1aMOlT45MPdVqVvOK3ZQ2hRj6NU0xm6nhE+QvJ1fqs9Ho4ugXmy7YKbZnbVTJuBhbN1uQEJyFbuP6w481XB9+/8HxWq4lsesVRG4Lwrpfcp2hP7dMSY3IQVeEayax8h6uhhtSARXCO5gRNSxqdE9NTTpAFkTq+xQ7xuSln+0F6/peyMhDg60+94xTGMuQDSVPhsdrYyUQNaGgYsDdx5yDJ+qPDzGSyKP4N24xPOZLIaZy0ttoHeXteNZZuutUV8LrG6L5OR261yO0dX5K3EqDYnsva3n/+kDl8wRY22kRFaNETADWAuIQqwYLdWBAVG/A=";
        // 解密
/*        String decryptStr = des.decryptStr(encryptHex);
        System.out.println(decryptStr);*/
    }

    /**
     * DES CBC解密数据
     * @param key 解密的密钥
     * @param content 要解密的内容
     */
    public static String desDecrypt(String key, String content) {
        DES des = new DES(Mode.CBC, Padding.PKCS5Padding, key.getBytes(), key.getBytes());
        return des.decryptStr(content);
    }

    public static void main(String[] args) {
        String key = "6HPjSZFH";

//        String content = "vmFqzzJ=zqkd_app&app_version=3.5.5&carrier=%E4%B8%AD%E5%9B%BD%E7%94%B5%E4%BF%A1&channel=c4130&device_brand=HONOR&device_id=56227628&device_model=YAL-AL10&device_platform=android&device_type=android&dpi=480&inner_version=202108181034&language=zh-CN&memory=7&mi=0&mobile_type=1&net_type=1&network_type=WIFI&oaid=b825038c-822f-4411-a734-2717f7929686&openudid=a81e321b771ed08b&os_api=29&os_version=YAL-AL10+10.1.0.162%28C00E160R8P12%29&request_time=1639405735&resolution=1080x2232&rom_version=YAL-AL10+10.1.0.162%28C00E160R8P12%29&s_ad=PCWwRj3eGxCw%3DtFr3v-In3uDP2BHXsUEsNBpnGfwEwD-m&sm_device_id=20210228151546a63b4b4bc70d322a9b4ff1ca30d3b43c0123c29822628dc8&storage=229.50&task_id=3750&uid=61114798&version_code=63&zqkey=MDAwMDAwMDAwMJCMpN-w09Wtg5-Bb36eh6CPqHualIejmK6Fqaqxp5duhnyp4LDPyGl9onqkj3ZqYJa8Y898najWsJupZLDdn2mEfIKWrqm2apqGcXY&zqkey_id=48cbdcba2efc186221f7882ccb781db3&sign=9fda79fbe5f6d70fedc60c351c211774";

/*        String content = "你好";
        String s = desEncrypt(key, content);
        System.out.println(s);*/





        String encryptHex = "v9KveHJhUlCagirF/fZxG3bF/mqByz8mLnx9GKOr61SIdGp4iFvCrhdM2Z5qfh2tN31qiYfehao32IOG6/oa0JbNfaM/Mts+e7Td7SSJg0lE/dyurhhgsr8oDltClckWZng80aYkCpmhoTDM3DzW1uF6X5Jibv+xzL3rWLsUZeoX/DQkN/VObs7ZO5UV9vaMNIYpZKMeETRjUp5knNJlffe8JQ2kYmJjpkBn3l3CmQlvTxhIcJ3WoyXlo6zOKl67ueattla9rPh1FXNBcwIqjGPSiN0LCViYoeiWTptsbLU9K8vvGxNbTkFEOi6AnJ1zOGZEFV+vjjqUUmZkBVagg5OWhYaEuIlyWzS79jyhXRHxxJckfwPLbEHq9/594Xwe1WLPvyyo9UezXJUmriN7Z60aZYRUK2bC2YuTHObj/CjkcyVpZa32GFcSIgu4azRU65bJA8iB3j+rQToyibR2EwZLYTHmEN4PiCE5iuKqZU2WHhaAIYx5krLnW1OFaeFNxNvUsa1PH+Efp/GdLQNMg4XmhA176kTwkI47fhHD8I90FNw3goklX56EyRPhLuyQYF5QaeXWH0tDGKYGgavL6UyfQvdHfuDlQ+M4/++kuguqqApzn47kkFSxFX0Nn12QnEBesLTJJcUZQi7I4sIlDGP1hxrtNMupgP/hhRqunOyUN9WoTR3+jp7b3Jb1E8mqut6Qpn23bZkvqosUSX0HEM/tipy1vFpucU0w2Xh2T1MwD8zngedWvGb7UwpAnU21SOGTsjqwRRucGAJdCOqNKsTRxEy+22sd8fxwcEIQC5OjpOdniZ8eRSLpYcpLh0LH8cBKceqQf/Eu17t1n5BGGgIBnB2q+IZ1jOsTNrFeftNP7uoZD+fPJ9GWJCOiIG2c7sCJo5QB0K1aMOlT45MPdVqVvOK3ZQ2hRj6NU0xm6nhE+QvJ1fqs9Ho4ugXmy7YKbZnbVTJuBhbN1uQEJyFbuP6w481XB9+/8HxWq4lsesVRG4Lwrpfcp2hP7dMSY3IQVeEayax8h6uhhtSARXCO5gRNSxqdE9NTTpAFkTq+xQ7xuSln+0F6/peyMhDg60+94xTGMuQDSVPhsdrYyUQNaGgYsDdx5yDJ+qPDzGSyKP4N24xPOZLIaZy0ttoHeXteNZZuutUV8LrG6L5OR261yO0dX5K3EqDYnsva3n/+kDl8wRY22kRFaNETADWAuIQqwYLdWBAVG/A=";
        String s = desDecrypt(key, encryptHex);
        //System.out.println("解密后:"+s);


        String msg = " vmFqzzJ=zqkd_app&app_version=3.5.5&carrier=%E4%B8%AD%E5%9B%BD%E7%94%B5%E4%BF%A1&channel=c4130&device_brand=HONOR&device_id=56227628&device_model=YAL-AL10&device_platform=android&device_type=android&dpi=480&inner_version=202108181034&language=zh-CN&memory=7&mi=0&mobile_type=1&net_type=1&network_type=WIFI&oaid=b825038c-822f-4411-a734-2717f7929686&openudid=a81e321b771ed08b&os_api=29&os_version=YAL-AL10+10.1.0.162%28C00E160R8P12%29&request_time=1639405735&resolution=1080x2232&rom_version=YAL-AL10+10.1.0.162%28C00E160R8P12%29&s_ad=PCWwRj3eGxCw%3DtFr3v-In3uDP2BHXsUEsNBpnGfwEwD-m&sm_device_id=20210228151546a63b4b4bc70d322a9b4ff1ca30d3b43c0123c29822628dc8&storage=229.50&task_id=3750&uid=61114798&version_code=63&zqkey=MDAwMDAwMDAwMJCMpN-w09Wtg5-Bb36eh6CPqHualIejmK6Fqaqxp5duhnyp4LDPyGl9onqkj3ZqYJa8Y898najWsJupZLDdn2mEfIKWrqm2apqGcXY&zqkey_id=48cbdcba2efc186221f7882ccb781db3&sign=9fda79fbe5f6d70fedc60c351c211774";
        String s1 = desEncrypt(key, msg);
        //System.out.println("加密后:"+s1);

    }

}
